﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using WebManager;

namespace BaoJian.WebManager.Function.ExProduct
{
    public partial class RankEdit : System.Web.UI.Page
    {
        /// <summary>
        /// 产品ID
        /// </summary>
        private string oid = null;
      
        /// <summary>
        /// 栏目ID
        /// </summary>
        private string ColumnID = null;

        private LYQ.BLL.Product productBll = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            oid = HttpContext.Current.Request.QueryString["OID"];
            ColumnID = HttpContext.Current.Request.QueryString["ColumnID"];

            if (!Page.IsPostBack)
            {

                LYQ.BLL.Rank bll = new LYQ.BLL.Rank();
                LYQ.Model.Rank model = bll.GetModel(new Guid(oid));
                txtSID.Text = model.SID.ToString();
                txtTotalNum.Text = model.TotalNum.ToString();
                Image1.ImageUrl = model.ImagePath;

                 //产品名称
                productBll = new LYQ.BLL.Product();
                drpPName.DataSource = productBll.GetList("");
                drpPName.DataBind();

                ListItem item = drpPName.Items.FindByValue(model.PID.ToString());
                item.Selected = true;

            }
        }

        protected void drpPName_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (drpPName.SelectedValue != "-1")
            {
                productBll = new LYQ.BLL.Product();
                LYQ.Model.Product productModel = productBll.GetModel(new Guid(drpPName.SelectedValue));

                Image1.ImageUrl = @"~\uploads\ExchangeProducts\" + productModel.SImg;
            }
            else
            {
                Image1.ImageUrl = "";
            }
        }

        protected void Save_Click(object sender, EventArgs e)
        {

            LYQ.BLL.Rank bll = new LYQ.BLL.Rank();
            LYQ.Model.Rank model = bll.GetModel(new Guid(oid));

            model.SID = Convert.ToInt32(txtSID.Text);
            model.PID = new Guid(drpPName.SelectedItem.Value);
            model.PName = drpPName.SelectedItem.Text;
            model.TotalNum = Convert.ToInt32(txtTotalNum.Text);
            Image1.ImageUrl = model.ImagePath;

            bll.Update(model);

            string url = URLUtility.UrlBase + "/WebManager/Function/ExProduct/rank/Rank.aspx?oid=" + ColumnID;
            Page.Response.Redirect(url);
        }

        protected void Cancle_Click(object sender, EventArgs e)
        {
            string url = URLUtility.UrlBase + "/WebManager/Function/ExProduct/rank/Rank.aspx?oid=" + ColumnID;
            Page.Response.Redirect(url);
        }
    }
}
